package com.study.springcloud.ribbon;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @Author raoluping
 * @Date 2017/10/26 14:39
 * @Description
 */
@Service
public class HelloService {
  @Autowired
  private RestTemplate restTemplate;

  private static final String servicename = "service-simple-provide";

  // 限流，当当前请求超时，失败，访问达到阈值，启动限流熔断
  // fallbackMethod 是指定限流后 程序改怎么处理
  @HystrixCommand(fallbackMethod = "hiError")
  public String sayHello(String name) {
    return restTemplate.getForObject("http://" + servicename + "/sayHi?name=" + name, String.class);
  }

  public String hiError(String name) {
    return "hi," + name + ",sorry,系统繁忙，请稍后再试!";
  }
}
